<template>
  <el-form ref="plan" :model="plan" label-width="80px">
    <el-form-item label="名称">
      <el-input v-model="plan.summary" />
    </el-form-item>
    <el-form-item label="详情">
      <el-input type="textarea" v-model="plan.detail" />
    </el-form-item>
    <el-form-item label="日期">
      <el-input v-model="day" :disabled="true" />
    </el-form-item>
    <el-form-item label="时间">
      <el-time-select
        v-model="plan.timeStart"
        :picker-options="{
          start: '06:00',
          end: '24:00',
          step: '00:10',
        }"
        placeholder="开始时间"
      ></el-time-select>
      -
      <el-time-select
        v-model="plan.timeEnd"
        :picker-options="{
          start: '06:00',
          end: '24:00',
          step: '00:10',
        }"
        placeholder="结束时间"
      ></el-time-select>
    </el-form-item>
    <el-form-item>
        <el-button type="primary" @click="close">关闭</el-button>
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: "plan_add_form",
  props: ["day"],
  data() {
    return {
      plan: {
        summary: "",
        detail: "",
        dateStart: "",
        timeStart: "",
        timeEnd: "",
        planType: "Day",
      },
    };
  },
  methods: {
    onSubmit: function () {
      this.plan.dateStart = this.day;
      this.plan.dateEnd = this.day;
      var _this = this;
      this.$axios.post("/plan/add", this.plan).then(function (response) {
        if ("OK" == response.data.code) {
           _this.$notify({
            title: '提示',
            type: 'success',
            message: '你已成功添加一条计划。'
          });
          _this.plan = {
            summary: "",
            detail: "",
            dateStart: "",
            timeStart: "",
            timeEnd: "",
            planType: "Day"
          };
          _this.$emit("addDialogClose",response.data.data);
        }else{
          _this.$notify({
            title: '提示',
            type: 'error',
            message: '新增失败，请重试。',
            duration: 0
          });
        }
      });
    },
    close:function(){
        this.plan = {
            summary: "",
            detail: "",
            dateStart: "",
            timeStart: "",
            timeEnd: "",
            planType: "Day"
          };
          this.$emit("addDialogClose");
    }
  },
};
</script>

<style>
</style>